package cn.bugstack.xfg.dev.tech.test;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.junit.Test;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Query;
//import java.util.regex.Pattern;
//import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class Retrofit2Test {

    @Test
    public void test_retrofit() {
        OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS);

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        httpClient.addInterceptor(loggingInterceptor);

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.zsxq.com/")
                .client(httpClient.build())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())
                .addConverterFactory(JacksonConverterFactory.create())
                .build();

        ApiService apiService = retrofit.create(ApiService.class);

        Call<String> call = apiService.getTopics("all", 1, "zsxq_access_token=E49B3922-5122-4422-BCAC-8C4A2C6214FE_2F994BA247C44F8E; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22198cb592b399d4-05c4952ce106f4-26061851-1382400-198cb592b3a2c2%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTk4Y2I1OTJiMzk5ZDQtMDVjNDk1MmNlMTA2ZjQtMjYwNjE4NTEtMTM4MjQwMC0xOThjYjU5MmIzYTJjMiJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%22198cb592b399d4-05c4952ce106f4-26061851-1382400-198cb592b3a2c2%22%7D; abtest_env=product");

        try {
            String response = call.execute().body();
            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    interface ApiService {
        @GET("https://api.zsxq.com/v2/groups/28885518425541/topics?scope=all&count=1")
        @Headers({
                "Accept-Encoding: gzip, deflate, br, zstd",
                "accept: application/json, text/plain, */*",
                "accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
                "authority: api.zsxq.com",
                "dnt: 1",
                "origin: https://wx.zsxq.com",
                "referer: https://wx.zsxq.com/",
                "sec-ch-ua: \"Chromium\";v=\"124\", \"Microsoft Edge\";v=\"124\", \"Not-A.Brand\";v=\"99\"",
                "sec-ch-ua-mobile: ?0",
                "sec-ch-ua-platform: \"Windows\"",
                "sec-fetch-dest: empty",
                "sec-fetch-mode: cors",
                "sec-fetch-site: same-site",
                "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0",
                "x-request-id: aeb4caf9d-c3f3-fdb9-bcba-7f01305b992",
                "x-signature: 7fe8847a8bd78ece71ba4674c641b10ff109ba6b",
                "x-timestamp:  1758108827",
                "x-version: 2.80.0"
        })
        Call<String> getTopics(@Query("scope") String scope, @Query("count") int count, @Header("cookie") String cookie);
    }

}
